/* eslint-disable max-classes-per-file */
/*
 * @Description:
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-08-15 10:44:30
 * @LastEditors: swc
 * @LastEditTime: 2025-02-14 13:41:44
 */

import { N_oSetupPanel } from '../types';

type I_compToolbar = N_oSetupPanel.N_comps.I_compToolbar;

export class T_toolbarLib {
  // 权限toobar区域
  private toolbarItem: Set<string> = new Set<string>([
    'insert',
    'default',
    'delete',
    'save',
    'import',
    'export',
    'exportXML',
    'globalSearch',
    'refresh',
    'edit',
    'print',
    'audit',
    'unaudit',
    'antiAudit',
    'openData',
    'pasteColumn',
    'pasteRow',
    'jumpFirst',
    'jumpLast',
    'next',
    'previous',
    'search',
    'requestAudit',
    'auditStatus',
    'expandAll',
    'contractAll',
    'mutiSelect',
    'open',
    'accountPosted',
    'cancelPost',
    'caseclosed',
    'anticlosing',
    'freeze',
    'unfreeze',
    'void',
    'addon'
  ]);

  private baseGrid: I_compToolbar = {
    insert: true,
    default: true,
    delete: true,
    save: true,
    import: true,
    export: true,
    exportXML: true,
    globalSearch: true,
    refresh: true,
    edit: true,
    print: true,
    audit: false,
    unaudit: false,
    requestAudit: false,
    auditStatus: false,
    // search: true,
    pasteColumn: false, //
    antiAudit: false,
    accountPosted: false,
    cancelPost: false,
    caseclosed: false,
    anticlosing: false,
    freeze: false,
    unfreeze: false,
    void: false,
    addon: []
  };

  private refBaseGrid: I_compToolbar = {
    insert: true,
    default: true,
    delete: true,
    save: true,
    import: true,
    export: true,
    exportXML: true,
    globalSearch: true,
    refresh: true,
    edit: true,
    print: true,
    // audit: false,
    // unaudit: false,
    search: true,
    pasteColumn: false,
    addon: []
  };

  private basePanel: I_compToolbar = {
    insert: true,
    delete: true,
    save: true,
    // import: true,
    // export: true,
    jumpFirst: true,
    jumpLast: true,
    next: true,
    previous: true,
    edit: true,
    print: true,
    refresh: true,
    audit: true,
    unaudit: true,
    antiAudit: false,
    search: true,
    requestAudit: false,
    auditStatus: false,
    accountPosted: false,
    cancelPost: false,
    caseclosed: false,
    anticlosing: false,
    freeze: false,
    unfreeze: false,
    void: false,
    // 1.0 关闭
    addon: []
  };

  private treeGrid: I_compToolbar = {
    default: true,
    expandAll: true,
    contractAll: true,
    mutiSelect: true,
    addon: []
  };

  private dateNav: I_compToolbar = {
    default: true
  };

  private grpah: I_compToolbar = {
    insert: true,
    default: true,
    delete: true,
    save: true,
    edit: true,
    audit: true,
    unaudit: true,
    antiAudit: true,
    open: true,
    addon: []
  };

  private refGrpah: I_compToolbar = {
    default: true,
    insert: true,
    delete: true,
    edit: true,
    save: true,
    open: true,
    addon: []
  };

  private cBaseForm: I_compToolbar = {
    // insert: true,
    // default: true,
    // delete: true,
    // save: true,
    // edit: true,
    // // audit: true,
    // print: true,
    // // antiAudit: true,
    // // open: true,
    // refresh: true,
    // addon: []
    insert: true,
    delete: true,
    save: true,
    import: true,
    export: true,
    jumpFirst: true,
    jumpLast: true,
    next: true,
    previous: true,
    edit: true,
    print: true,
    search: true,
    addon: []
  };

  private baseView: I_compToolbar = {
    // insert: false,
    // delete: false,
    // save: false,
    // edit: false,
    // import: false,
    default: true,
    export: true,
    globalSearch: true,
    refresh: true,
    print: true,
    search: true,
    expandAll: true,
    exportXML: true,
    // contractAll: true,
    // mutiSelect: false,
    addon: []
  };

  private refComp: I_compToolbar = {
    default: true,
    export: true,
    globalSearch: true,
    refresh: true,
    print: true,
    pasteColumn: true,
    jumpFirst: true,
    jumpLast: true,
    next: true,
    previous: true,
    search: true,
    requestAudit: false,
    expandAll: true,
    contractAll: true,
    mutiSelect: false,
    addon: []
  };

  private multiForm: I_compToolbar = {
    insert: true, // 新增行 在每一行
    delete: true, // 删除行 在每一行
    refresh: true, // 刷新所有  在toolbar
    save: true, // 保存所有 在toolbar
    edit: true // 编辑行 在每一行
    // addon: [] // 在toolbar
  };

  /**
   * @description: 库验证
   * @param {I_defToolbarVal} itm
   * @return {*}
   * @author: wiz
   * @Date: 2023-08-16 18:13:48
   * @LastEditors: wiz
   * @LastEditTime: Do not edit
   */
  private chkItm(itm: I_compToolbar): I_compToolbar {
    Object.keys(itm).forEach(k => {
      if (!this.toolbarItem.has(k)) {
        delete itm[k];
      }
    });
    return itm;
  }

  public getCompToolBarSet(
    mode: N_oSetupPanel.N_comps.COMP_NAME
  ): I_compToolbar {
    switch (mode) {
      case N_oSetupPanel.N_comps.COMP_NAME.BASE_GRID:
        return this.chkItm(this.baseGrid);
      case N_oSetupPanel.N_comps.COMP_NAME.BASE_PANEL:
        return this.chkItm(this.basePanel);
      case N_oSetupPanel.N_comps.COMP_NAME.TREE_GRID:
        return this.chkItm(this.treeGrid);
      case N_oSetupPanel.N_comps.COMP_NAME.DATE_NAV:
        return this.chkItm(this.dateNav);
      case N_oSetupPanel.N_comps.COMP_NAME.GRAPH:
        return this.chkItm(this.grpah);
      case N_oSetupPanel.N_comps.COMP_NAME.C_BASE_FORM:
        return this.chkItm(this.cBaseForm);
      case N_oSetupPanel.N_comps.COMP_NAME.BASE_VIEW:
        return this.chkItm(this.baseView);
      case N_oSetupPanel.N_comps.COMP_NAME.REF_COMP:
        return this.chkItm(this.refComp);
      case N_oSetupPanel.N_comps.COMP_NAME.MULTI_FORM:
        return this.chkItm(this.multiForm);
      case N_oSetupPanel.N_comps.COMP_NAME.REF_GRAPH:
        return this.chkItm(this.refGrpah);
      case N_oSetupPanel.N_comps.COMP_NAME.REF_BASE_GRID:
        return this.chkItm(this.refBaseGrid);
      default:
        throw new Error('不能识别的类型');
    }
  }
}
